/* util.c --- 
 * 
 * @file util.c
 * @brief 
 * @author Molnár Zoltán
 * @date Sat Jan 25 15:41:49 2014 (+0100)
 * Version: 
 * Last-Updated: Sun Feb  2 20:36:32 2014 (+0100)
 *           By: Molnár Zoltán
 * 
 */

/* This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301, USA.
 */

/*******************************************************************************/
/* INCLUDES                                                                    */
/*******************************************************************************/
#include "util.h"

/*******************************************************************************/
/* DEFINED CONSTANTS                                                           */
/*******************************************************************************/


/*******************************************************************************/
/* MACRO DEFINITIONS                                                           */
/*******************************************************************************/


/*******************************************************************************/
/* TYPE DEFINITIONS                                                            */
/*******************************************************************************/


/*******************************************************************************/
/* DEFINITIONS OF GLOBAL CONSTANTS AND VARIABLES                               */
/*******************************************************************************/


/*******************************************************************************/
/* DEFINITION OF LOCAL FUNCTIONS                                               */
/*******************************************************************************/


/*******************************************************************************/
/* DEFINITION OF GLOBAL FUNCTIONS                                              */
/*******************************************************************************/
/**
 *
 */
uint32_t UTL_u32AtoI( unsigned char *pucStr, uint32_t u32Length)
{

}

/**
 * Convert uint32_t to ASCII characters
 *
 * @param[in] pucStr Pointer to the result string. User must ensure that it is large
 *                   enough to store the result
 * @param[in] u32Num Number to convert to ASCII
 */
uint32_t UTL_u32ItoA( unsigned char *pucStr, uint32_t u32Num)
{
  uint32_t u32i, u32j;

  for( u32i = 0; u32Num; u32i++)
    {
      pucStr[u32i] = '0' + (u32Num % 10);
      u32Num /= 10;
    }

  /* Swap character order */
  for( u32j = 0; u32j < (u32i / 2); u32j++)
    {
      uint8_t u8t = pucStr[u32j];
      pucStr[u32j] = pucStr[u32i - u32j - 1];
      pucStr[u32i - u32j - 1] = u8t;
    }

  /* Terminate the string */
  pucStr[u32i] = '\0';

  /* Return the length of the string including the trailing '\0' */
  return (u32i + 1);

  return 0;
}

/**
 * Convert double to ASCII characters with a precision determined by input parameter
 */
uint32_t UTL_u32DtoA( unsigned char *pucStr, double dNum, uint32_t u32Frac)
{
  uint32_t u32Conv = (uint32_t) (dNum * MTH_u32Pow( 10, u32Frac));
  uint32_t u32Length = UTL_u32ItoA( pucStr, u32Conv);
  uint32_t u32i = 0;

  /* Insert space for decimal point */
  for( u32i = 0; u32i < u32Frac; u32i++)
      pucStr[u32Length - u32i - 1] = pucStr[u32Length - u32i - 2];

  /* Insert decimal point */
  pucStr[u32Length - u32Frac - 1] = '.';

  /* Terminate string */
  pucStr[u32Length] = '\0';

  /* Return the length of the string including the trailing \0 */
  return u32Length + 1;
}


/******************************* END OF FILE ***********************************/

